import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/home/Index.vue'

const originalPush = VueRouter.prototype.push

VueRouter.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
    children: [
      {
        path: '/page',
        name: 'Page',
        component: () => import('../views/page/Index.vue')
      },
      {
        path: '/gankio',
        name: 'Gankio',
        component: () => import('../views/gankio/Index.vue')
      }, {
        path: '/articleDetailIndex',
        name: 'ArticleDetailIndex',
        component: () => import('../views/gankio/article/ArticleDetailIndex.vue')
      }, {
        path: '/girlIndex',
        name: 'GirlIndex',
        meta: {
          keepAlive: true
        },
        component: () => import('../views/gankio/girl/Index.vue')
      }, {
        path: '/girlDetailIndex',
        name: 'GirlDetailIndex',
        component: () => import('../views/gankio/girl/GirlDetailIndex.vue')
      }, {
        path: '/about',
        name: 'About',
        component: () => import('../views/about/About.vue')
      }
    ]
  }
]

const router = new VueRouter({
  mode: 'history',
  scrollBehavior (to, from, savePosition) {
    /* if (savePosition) {
       return savePosition
     } else {
       return {
         x: 0,
         y: 0
       }
     }*/
    return {
      x: 0,
      y: 0
    }
  },
  base: process.env.BASE_URL,
  routes
})

export default router
